package com.lex.controller;

import com.lex.common.api.CommonResult;
import com.lex.entity.params.CmsLoginParams;
import com.lex.entity.user.LogoutDto;
import com.lex.service.BaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@Slf4j
@Controller
@RequestMapping("/")
@Tag(name = "BaseController", description = "基础接口")
public class BaseController {

    @Autowired
    private BaseService baseService;

    @Operation(summary = "登录")
    @PostMapping(value = "/login")
    @ResponseBody
    public CommonResult login(@Validated @RequestBody CmsLoginParams CmsLoginParams){
        return baseService.login(CmsLoginParams.getUsername(), CmsLoginParams.getPassword());
    }

    @Operation(summary = "获取用户信息")
    @ResponseBody
    @RequestMapping(value = "/getUserInfo", method = RequestMethod.GET)
    public CommonResult getUserInfo(){
        return baseService.getLoginUserInfo();
    }

    @Operation(summary = "退出登录")
    @ResponseBody
    @RequestMapping(value = "/logout", method = RequestMethod.POST)
    public CommonResult logout(@Validated @RequestBody LogoutDto logoutDto){
        return baseService.logout(logoutDto.getToken());
    }

}
